/* 
 * Copyright 2014 Josef Hertl.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package caetus.modelChecking.transition;

import caetus.modelChecking.variable.ModelBaseVariable;
import caetus.modelChecking.variable.ModelVariable;
import caetus.modelChecking.variable.ModelVariableType;


/**
 *
 * @author Josef Hertl
 */
public class TransitionAction {

    private final TransitionActionEnum actionEnum;
    private ModelVariable[] variables;
    private int intArgument = 0;
    private boolean boolArgument = false;

    public TransitionAction(TransitionActionEnum actionEnum, ModelVariable[] variables, int intArgument, boolean boolArgument) {
        this.actionEnum = actionEnum;
        this.variables = variables;
        this.intArgument = intArgument;
        this.boolArgument = boolArgument;
    }

    /**
     * Automatically assumes this is a state change.
     *
     * @param intArgument The required state number.
     */
    public TransitionAction(int intArgument) {
        this.actionEnum = TransitionActionEnum.CHANGE_STATE;
        this.intArgument = intArgument;
    }

    /**
     * Shortcode for input text command (i.e. generate_symmetric).
     */
    public TransitionAction(String text) {
        this.actionEnum = TransitionActionEnum.RECEIVE_COMMAND;
        this.variables = new ModelVariable[]{new ModelBaseVariable(text, ModelVariableType.TEXT)};
    }

    /**
     * Shortcode for plain transition recognizable by transition type. Example:
     * ALL_SECRETS.
     */
    public TransitionAction(TransitionActionEnum tae) {
        this.actionEnum = tae;
        this.variables = new ModelVariable[]{};
    }

    /**
     * Shortcode for command word and boolean variable.
     */
    public TransitionAction(String text, ModelVariable condition) {
        this.actionEnum = TransitionActionEnum.RECEIVE_COMMAND_WITH_CONDITION;
        this.variables = new ModelVariable[]{new ModelBaseVariable(text, ModelVariableType.TEXT), condition};
    }

    public TransitionAction(TransitionActionEnum transitionActionEnum, ModelVariable variable) {
        this.actionEnum = transitionActionEnum;
        this.variables = new ModelVariable[]{variable};
    }

    /**
     * Used mostly for sending encrypted variables.
     */
    public TransitionAction(TransitionActionEnum transitionActionEnum, ModelVariable variableA, ModelVariable variableB) {
        this.actionEnum = transitionActionEnum;
        this.variables = new ModelVariable[]{variableA, variableB};
    }

    public TransitionAction(TransitionActionEnum transitionActionEnum, ModelVariable variable, boolean inputBoolArgument) {
        this.actionEnum = transitionActionEnum;
        this.variables = new ModelVariable[]{variable};
        this.boolArgument = inputBoolArgument;
    }

    public TransitionAction(TransitionActionEnum actionEnum, ModelVariable[] variables) {
        this.actionEnum = actionEnum;
        this.variables = variables;
    }

    public TransitionAction(TransitionActionEnum actionEnum, ModelVariable[] variables, boolean boolArgument) {
        this.actionEnum = actionEnum;
        this.variables = variables;
        this.boolArgument = boolArgument;
    }

    /**
     * Performs the transition.
     *
     * @return hlpsl-ready transition action with the specified attributes.
     */
    public String perform() {
        return actionEnum.makeTransitionAction(variables, intArgument, boolArgument);
    }
}
